package com.mujin.keji.collectionsystem.module.main.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.listeners.CustomItemClickListener;
import com.mujin.keji.collectionsystem.listeners.FunctionItemClickListener;
import com.mujin.keji.collectionsystem.module.main.dto.FunctionDto;
import com.mujin.keji.collectionsystem.module.main.dto.TripDto;
import com.mujin.keji.collectionsystem.module.tripplan.dto.QueryPlanDto;

import java.util.List;

/**
 * 行程规划首页列表适配器
 *
 * @author weishixiong
 * @Time 2018-03-21
 */

public class TripPlanningAdapter extends RecyclerView.Adapter<TripPlanningAdapter.ViewHolder> {
    private Activity mContext;
    private List<QueryPlanDto> datas;
    private CustomItemClickListener listener;

    public TripPlanningAdapter(Activity context, List<QueryPlanDto> datas, CustomItemClickListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_trip_planning, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tv_trip_name.setText(datas.get(position).getTitle());
        holder.tv_city_zero.setText(datas.get(position).getAddressCity() + " " + (datas.get(position).getAddressDistrict()==null?"":datas.get(position).getAddressDistrict()));
        holder.ll_item_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onItemClick(null, position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public TextView tv_city_zero;
        public TextView tv_trip_name;
        public RelativeLayout ll_item_view;


        public ViewHolder(View itemView) {
            super(itemView);
            tv_city_zero = (TextView) itemView.findViewById(R.id.tv_city_zero);
            tv_trip_name = (TextView) itemView.findViewById(R.id.tv_trip_name);
            ll_item_view = (RelativeLayout) itemView.findViewById(R.id.ll_item_view);


        }

    }
}
